package com.example.share.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.share.mapper.CategoryGoodMapper;
import com.example.share.mapper.CategoryMapper;
import com.example.share.mapper.GoodMapper;
import com.example.share.mapper.UserMapper;
import com.example.share.pojo.Category;
import com.example.share.pojo.CategoryGood;
import com.example.share.pojo.Good;
import com.example.share.pojo.User;
import com.example.share.service.SubmitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SubmitServiceImpl implements SubmitService {
    @Autowired
    private GoodMapper goodMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CategoryGoodMapper categoryGoodMapper;
    //添加物品
    @Override
    public Integer addGood(Good good) {
//        QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
        //查询名字为 Tom 的一条记录
//        queryWrapper.eq("good_id",good.getGoodId());
//        queryWrapper.eq("good_name",good.getGoodName());
//        queryWrapper.eq("good_number",good.getGoodNumber());
//        queryWrapper.eq("good_status",good.getGoodStatus());
//        queryWrapper.eq("good_add_time",good.getGoodAddTime());
//        queryWrapper.eq("good_access_degree",good.getGoodAccessDegree());
//        queryWrapper.eq("good_is_deleted",good.getGoodIsDeleted());
//        queryWrapper.eq("good_id",good.getGoodId());
        Integer  operate_prompt= goodMapper.insert(good);
        return operate_prompt;
    }
    //查询分类
    @Override
    public Category findCategory(String category){
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        //查询名字为 Tom 的一条记录
        queryWrapper.eq("category_name",category);
        Category category1 = categoryMapper.selectOne(queryWrapper);
        System.out.println(category1+"2222222222");
        return category1;
    }

    //添加分类
    @Override
    public Integer addCategory(String category) {
        long  j=1;
        Category category1 = new Category(category,j,true) ;

        Integer  operate_prompt= categoryMapper.insert(category1);
        return operate_prompt;
    }
    //修改user贡献度
    @Override
    public int  reviseUser(User user) {
        int i =   userMapper.updateById(user);
        return i;
    }
    //查询用户信息
    @Override
    public User finduser(int userId ){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        //查询名字为 Tom 的一条记录
        queryWrapper.eq("user_id",userId);
        User user = userMapper.selectOne(queryWrapper);
        System.out.println(user);
        return user;

    }
    //添加中间表
    @Override
    public Integer addCategoryGood(CategoryGood categoryGood) {
        Integer  operate_prompt= categoryGoodMapper.insert(categoryGood);
        return operate_prompt;
    }

    //查询物品--分类中间表
    @Override
    public CategoryGood findCategoryGood(long goodId) {
        QueryWrapper<CategoryGood> queryWrapper = new QueryWrapper<>();
        //查询名字为 Tom 的一条记录
        queryWrapper.eq("good_id",goodId);
        CategoryGood categoryGood = categoryGoodMapper.selectOne(queryWrapper);
        System.out.println(categoryGood);
        return categoryGood;
    }



    //查询物品
    @Override
    public Good findGood(String name) {
        QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
        //查询名字为 Tom 的一条记录
        queryWrapper.eq("good_name",name);
        Good good = goodMapper.selectOne(queryWrapper);
        System.out.println(good);
        return good;
    }

    //修改物品信息
    @Override
    public int reviseGood(Good good) {
        System.out.println("555555555555");
        int i =   goodMapper.updateById(good);
        System.out.println("5555");
        return i;
    }
}
